package com.book.warehouse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.book.common.annotation.ControllerEndpoint;
import com.book.common.annotation.Log;
import com.book.common.controller.BaseController;
import com.book.common.entity.FebsConstant;
import com.book.common.entity.FebsResponse;
import com.book.common.entity.QueryRequest;
import com.book.common.utils.FebsUtil;
import com.book.shelves.entity.ShelvesApply;
import com.book.shelves.service.ShelvesApplyService;
import com.book.system.entity.User;
import com.book.warehouse.entity.WarehouseBook;
import com.book.warehouse.entity.WarehouseHouseBook;
import com.book.warehouse.service.WarehouseBookService;
import com.book.warehouse.service.WarehouseHouseBookService;
import com.wuwenze.poi.ExcelKit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: 刘恬镯
 * @Description: 20174052
 */

@Controller
public class WarehouseHouseBookController extends BaseController {

    @Autowired
    WarehouseHouseBookService warehouseHouseBookService;
    @Autowired
    ShelvesApplyService shelvesApplyService;
    @Autowired
    WarehouseBookService warehouseBookService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "warehouse/warehouseBookHouse")
    public String warehouseBookIndex() {
        return FebsUtil.view("warehouse/warehouseBookHouse/warehouseBookHouseList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "warehouse/warehouseBook/see/{id}")
    public String warehouseBookUpdate(@PathVariable Integer id, ModelMap modelMap) {
        List<WarehouseHouseBook> wareList = this.warehouseHouseBookService.wareList(id);
        modelMap.put("warehouseBook", wareList);
        return FebsUtil.view("warehouse/warehouseBookHouse/warehouseBookHouseSeeList");
    }

    @GetMapping("warehouseBookList/excel/{id}")
    @RequiresPermissions("warehouseHouse:update")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败")
    public void export(@PathVariable String id, HttpServletResponse response) {
        List<WarehouseHouseBook> wareList = this.warehouseHouseBookService.wareList(Integer.valueOf(id));
        ExcelKit.$Export(WarehouseBook.class, response).downXlsx(wareList, false);
    }
}
